package editor.project;

import java.awt.Color;
import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import editor.project.ProjectFile.Type;

/**
 * @author Mark Dessain
 */
@SuppressWarnings("serial")
public class ProjectTreeRenderer extends DefaultTreeCellRenderer 
{
    
	private ImageIcon folderOpen = new ImageIcon("graphics/icons/folder_page_white.png");
	private ImageIcon folderClosed = new ImageIcon("graphics/icons/folder.png");
	private ImageIcon folderSource = new ImageIcon("graphics/icons/folder_edit.png");
	private ImageIcon packageOpen = new ImageIcon("graphics/icons/package_go.png");
	private ImageIcon packageClosed = new ImageIcon("graphics/icons/package.png");
	private ImageIcon packageEmpty = new ImageIcon("graphics/icons/package_empty.jpg");
	private ImageIcon filePlain = new ImageIcon("graphics/icons/page_white_text.png");
	private ImageIcon fileJava = new ImageIcon("graphics/icons/page_white_code.png");
	

    /**
     *  Set Project Tree Renderer
     */
    public ProjectTreeRenderer() {
            setBorderSelectionColor(null);
            setBackgroundNonSelectionColor(null);
    }
    
    /* (non-Javadoc)
     * @see javax.swing.tree.DefaultTreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
     */
    public Component getTreeCellRendererComponent(JTree tree, Object value,boolean sel,boolean expanded,boolean leaf, int row,boolean hasFocus) 
    {
    	super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
	
    	Object node = ((DefaultMutableTreeNode)value).getUserObject();
    	
    	// TODO set as a hashmap instead of an if statement
    	// (Maybe, unsure if this will work)
    	
    	if(node instanceof ProjectFile)
    	{
    		ProjectFile file = (ProjectFile)node;
    		
    		if(file.getType() == Type.SRC)
    		{
        		setIcon(folderSource);
    		}
    		else if(file.getType() == Type.PACKAGE && expanded)
    		{
        		setIcon(packageOpen);
    		}
    		else if(file.getType() == Type.PACKAGE && !expanded)
    		{
        		setIcon(packageClosed);
    		}
    		else if(file.getType() == Type.PACKAGEEMPTY)
    		{
        		setIcon(packageEmpty);
    		}
    		else if(file.getType() == Type.FOLDER && expanded)
    		{
        		setIcon(folderOpen);
    		}
    		else if(file.getType() == Type.FOLDER && !expanded)
    		{
        		setIcon(folderClosed);
    		}
    		else if(file.getType() == Type.JAVA)
    		{
    			setIcon(fileJava);
    		}
    		else if(file.getType() == Type.FILE)
    		{
        		setIcon(filePlain);    			
    		}

    	}
    	else
    	{
    		
    		if(expanded)
    		{
    			setIcon(folderOpen);
    		}	
    		else
    		{
    			setIcon(folderClosed);
    		}
    		
    	}
    	
	    return this; 
    	

	}

    /* (non-Javadoc)
     * @see java.awt.Component#getBackground()
     */
    @Override
    public Color getBackground() {
            return null;
    }
}
